<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<%
	String path = request.getContextPath();
    //用户登陆
    String fphone = (String)request.getParameter("fphone"); 
    
    System.out.println("----------" + fphone);
%>
<title>血压监测-综合管理</title>
<link rel="stylesheet" type="text/css"
	href="<%=path%>/css/btn_class.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/ext-2.2/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/ext-2.2/style.css" />
<script type="text/javascript"
	src="<%=path%>/ext-2.2/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="<%=path%>/ext-2.2/ext-all.js"></script>
 <script type="text/javascript" src="<%=path%>/ext-2.2/build/locale/ext-lang-zh_CN.js"></script>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src = "<%=path%>/FusionCharts/FusionCharts.js"></script>
	<script type="text/javascript" src = "<%=path%>/FusionCharts/FusionChartsExportComponent.js"></script>
	<script type="text/javascript" src="<%=path%>/js/datepicker/WdatePicker.js" defer="defer"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
	
</body>
<script type="text/javascript">
	Ext.BLANK_IMAGE_URL = "<%=path%>/ext-2.2/resources/images/default/s.gif";
	Ext.QuickTips.init();// 为组件提供提示信息功能，form的主要提示信息就是客户端验证的错误信息。
    Ext.form.Field.prototype.msgTarget='side'; 

	var user_phone = '<%=fphone%>';

	Ext.onReady(function() {
				Ext.QuickTips.init();
				
				var Jthtwb = Ext.data.Record.create([ {
					name : 'fpid',
					mapping : 'fpid',
					type : 'string'
				}, {
					name : 'fname',
					mapping : 'fname',
					type : 'string'
				}, {
					name : 'fstate',
					mapping : 'fstate',
					type : 'string'
				}, {
					name : 'fsex',
					mapping : 'fsex',
					type : 'string'
				}, {
					name : 'fphone1',
					mapping : 'fphone1',
					type : 'string'
				}, {
					name : 'fssy',
					mapping : 'fssy',
					type : 'string'
				}, {
					name : 'fszy',
					mapping : 'fszy',
					type : 'string'
				}, {
					name : 'fxl',
					mapping : 'fxl',
					type : 'string'
				}, {
					name : 'fxtnd',
					mapping : 'fxtnd',
					type : 'string'
				}, {
					name : 'fdate',
					mapping : 'fdate',
					type : 'string'
				}, {
					name : 'frdate',
					mapping : 'frdate',
					type : 'string'
				} ]);

				var ds = new Ext.data.Store({
					reader : new Ext.data.JsonReader({
						totalProperty : 'totalProperty',
						root : 'root'
					}, Jthtwb),
					idProperty : 'threadid',
					remoteSort : true,
					url : 'xyj!queryXyjRecord.do'
				});


				//定义勾选框，不需要可不必定义
				var sm = new Ext.grid.CheckboxSelectionModel({
					singleSelect : true //单选
				});

				//定义列
				var colM = new Ext.grid.ColumnModel([ 
				    {
						header : '数据接收日期',
						dataIndex : 'frdate',
						width : 100,
						renderer : function(value) {
								if (value == null || value == "null") {
									return "";
								} else {
									return value;
								}
							}
					}, {
						header : '收缩压',
						dataIndex : 'fssy',
						width : 100,
						renderer : function(value) {
								if (value == null || value == "null") {
									return "";
								} else {
									return value + " /mmHg";
								}
							}
					}, {
						header : '舒张压',
						dataIndex : 'fszy',
						width : 100,
						renderer : function(value) {
								if (value == null || value == "null") {
									return "";
								} else {
									return value + " /mmHg";
								}
							}
					}, {
						header : '心率',
						dataIndex : 'fxl',
						width : 100,
						renderer : function(value) {
								if (value == null || value == "null") {
									return "";
								} else {
									return value + " /min";
								}
							}
					} ]);

				
				//生成表格
				var grid = new Ext.grid.GridPanel({
					closable : false,
					region : 'center',
					height : 350,
					autoWidth : true,
					stripeRows : true,
					//title : '角色列表',
					cm : colM,
					ds : ds,
					sm : sm,
					listeners : {
						'rowdblclick' : function(grid, row) { //双击打开
							var record = grid.getSelectionModel().getSelected();
							if (record) {
								show_chart_fun(record.data.fphone1, record.data.fname);
							}
						}
					},
					bbar : new Ext.PagingToolbar({
				        pageSize: 50,
				        store: ds,
				        displayInfo: true,
				        displayMsg: '共 {2} 条',
				        emptyMsg: "没有记录"
				    })
				});
				
				var detailsPanel = {
					id: 'details-panel',
			        region: 'center',
			        bodyStyle: 'padding-bottom:15px;background:#FFFFFF;',
					autoScroll: true,
					html: '<table><tr><td id="chartdiv1"><td/></tr><tr><td height="20"><td/></tr><tr><td id="chartdiv2"><td/></tr></table>'
			    };
			    
				var btn_close = new Ext.Button({
					text : '关闭',
					iconCls : 'sy-reset',
					handler : function() {
						chart_window.close();
					}
				});
				
				var panel_right = new Ext.Panel({
					region: "east",
					split:true,
		            minSize: 105,
		            maxSize: 500,
		            title : '历史数据',
		            collapsible: true,
		            collapsed: true, //展开或关闭
		            margins:'0 0 0 0',
		            layout:'fit',
		            layoutConfig:{
		                animate:true
		            },
					items :[ grid ],
					width:350
			   });
			   
			   
			   var chart_bdate = new Ext.form.DateField({
					fieldLabel : '开始日期',
					format: 'Y-m-d',
					id:'fbdate_id_chart',
					name:'fbdate',
					width : 100,
					style:"cursor:pointer;color:blue"
					
				});
			
	           var chart_edate = new Ext.form.DateField({
	   				fieldLabel : '结束日期',
	   				format: 'Y-m-d',
	   				id:'fedate_id_chart',
					name:'fedate',
					width : 100,
					value : new Date().format('Y-m-d'),
	   				style:"cursor:pointer;color:blue"
	   				
	   			});
			   
	   			
	   			var btn_search_chart = new Ext.Button({
					text : '查询',
					iconCls : 'sy-search',
					handler : function(btn) {
						
					document.getElementById("chartdiv1").innerHTML = "";
					document.getElementById("chartdiv2").innerHTML = "";	
						
					//血压曲线图
					Ext.Ajax.request({     
						url : 'xyj!produceXyjToChart.do',     
						method : 'POST',     
						params : {        
							'fphone1' : user_phone,        
							'fname' : '',
							'fbtime' : Ext.get('fbdate_id_chart').dom.value, 
							'fetime' : Ext.get('fedate_id_chart').dom.value  
							},     
						success : function(response, action) {        
							var myChart;        
							var responseText = response.responseText; 
							var pattern = new RegExp("^[\\s]+","gi");
        					var chart_data = responseText.replace(pattern,"");
							var myChart = new FusionCharts("../FusionCharts/MSLine.swf", "myChartId1", "850", "370", "0", "1");
							myChart.setDataXML(chart_data);
							myChart.render("chartdiv1");
						},     
						failure : function() {        
							Ext.Msg.alert('错误', '服务器出现错误请稍后再试！');     
						}  
					});  
					
					}
				});
				
				var btn_setting_save = new Ext.Button({
					text : '保存',
					iconCls : 'sy-sure',
					handler : function(btn) {
						//保存血压设置信息
						Ext.Ajax.request({     
							url : 'xyj!saveXyjOfSetting.do',     
							method : 'POST',     
							params : {        
								'fphone1' : user_phone,        
								'fssy_low' : Ext.get('fssy_low_id').dom.value,
								'fssy_high' : Ext.get('fssy_high_id').dom.value, 
								'fszy_low' : Ext.get('fszy_low_id').dom.value,
								'fszy_high' : Ext.get('fszy_high_id').dom.value, 
								'fxl_low' : Ext.get('fxl_low_id').dom.value,
								'fxl_high' : Ext.get('fxl_high_id').dom.value, 
								'fmyc_low' : Ext.get('fmyc_low_id').dom.value,
								'fmyc_high' : Ext.get('fmyc_high_id').dom.value 
								  
								},     
							success : function(response, action) {        
                                Ext.Msg.alert('提示', '保存成功！');    
							},     
							failure : function() {        
								Ext.Msg.alert('错误', '服务器出现错误请稍后再试！');     
							}  
						});
					}
				});
			
			    var oneTbar = new Ext.Toolbar({
					items:[ '心率(/min)：', {
						xtype : 'numberfield',
						id : 'fxl_low_id',
						name : 'fxl_low',
						style:"cursor:pointer;color:blue",
						value : '60',
						width : 60
					}, '~', {
						xtype : 'numberfield',
						id : 'fxl_high_id',
						name : 'fxl_high',
						style:"cursor:pointer;color:blue",
						value : '100',
						width : 60
					}, '-', '脉压差(/mmHg)：', {
						xtype : 'numberfield',
						id : 'fmyc_low_id',
						name : 'fmyc_low',
						style:"cursor:pointer;color:blue",
						value : '20',
						width : 60
					}, '~', {
						xtype : 'numberfield',
						id : 'fmyc_high_id',
						name : 'fmyc_high',
						style:"cursor:pointer;color:blue",
						value : '100',
						width : 60
					}, '-', btn_setting_save ]
			    });
			    
			    var twoTbar = new Ext.Toolbar({
					items:[ '开始日期：', chart_bdate, '-', '截止日期：',chart_edate, '-', btn_search_chart ]
			    });
					
			    var panel = new Ext.Panel({
			    	region: "center",
					layout:'fit',
					border : true,
					margins:'0 5 0 0',
					tbar : [ '收缩压(/mmHg)：', {
						xtype : 'numberfield',
						id : 'fssy_low_id',
						name : 'fssy_low',
						style:"cursor:pointer;color:blue",
						value : '90',
						width : 60
					}, '~', {
						xtype : 'numberfield',
						id : 'fssy_high_id',
						name : 'fssy_high',
						style:"cursor:pointer;color:blue",
						value : '140',
						width : 60
					}, '-', '舒张压(/mmHg)：', {
						xtype : 'numberfield',
						id : 'fszy_low_id',
						name : 'fszy_low',
						style:"cursor:pointer;color:blue",
						value : '60',
						width : 60
					}, '~', {
						xtype : 'numberfield',
						id : 'fszy_high_id',
						name : 'fszy_high',
						style:"cursor:pointer;color:blue",
						value : '90',
						width : 60
					} ],
					listeners : {
						'render' : function(){
							oneTbar.render(this.tbar); 
							twoTbar.render(this.tbar); 
						}
				 	},
					items : [ detailsPanel]
				});
				
				var viewport = new Ext.Viewport({
					layout : 'border',
					items : [ panel ]
				});
				
				//血压曲线图
				Ext.Ajax.request({     
					url : 'xyj!produceXyjToChart.do',     
					method : 'POST',     
					params : {        
						'fphone1' : user_phone,        
						'fname' : '',
						'fbtime' : Ext.get('fbdate_id_chart').dom.value, 
						'fetime' : Ext.get('fedate_id_chart').dom.value  
						},     
					success : function(response, action) {        
						var myChart;        
						var responseText = response.responseText; 
						var pattern = new RegExp("^[\\s]+","gi");
       					var chart_data = responseText.replace(pattern,"");
						var myChart = new FusionCharts("../FusionCharts/MSLine.swf", "myChartId1", "850", "370", "0", "1");
						myChart.setDataXML(chart_data);
						myChart.render("chartdiv1");
					},     
					failure : function() {        
						Ext.Msg.alert('错误', '服务器出现错误请稍后再试！');     
					}  
				});  
			
			
				Ext.Ajax.request({     
					url : 'xyj!getPatientSettingInfoByPhone.do',     
					method : 'POST',     
					params : {        
						'fphone1' : user_phone        
						},     
					success : function(response, action) {        
						var responseText = response.responseText; 
						var result = Ext.util.JSON.decode(response.responseText).root;
						for (var i = 0; i < result.length; i++) { 
				            //alert(result[i]["fssy_low"]); 
				            Ext.get('fssy_low_id').dom.value = result[i]["fssy_low"];
				            Ext.get('fssy_high_id').dom.value = result[i]["fssy_high"];
							Ext.get('fszy_low_id').dom.value = result[i]["fszy_low"];
				            Ext.get('fszy_high_id').dom.value = result[i]["fszy_high"];
				            Ext.get('fxl_low_id').dom.value = result[i]["fxl_low"];
				            Ext.get('fxl_high_id').dom.value = result[i]["fxl_high"];
				            Ext.get('fmyc_low_id').dom.value = result[i]["fmyc_low"];
				            Ext.get('fmyc_high_id').dom.value = result[i]["fmyc_high"];
						}
					},     
					failure : function() {        
						// Ext.Msg.alert('错误', '服务器出现错误请稍后再试！');     
					}  
				});  
			});
			
			
					
					
</script>


</html>